import { TRuneManual } from "../../../../../../Message/Db/Tables/TRuneManual";
import { SkillRuneHandbookRuneItem } from "./SkillRuneHandbookRuneItem";
import { RuneUtil } from "../RuneUtil";
import { ObjCreate } from "../../../common/ObjCreate";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { Language } from "../../../../../../extend/language/Language";
import { ObjectPool } from "../../../../../../com/gengine/utils/pools/ObjectPool";
import { FlyFootBmp } from "../../../mapUI/flyFoot/FlyFootBmp";
import { Cache } from "../../../../cache/Cache";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { MsgManager } from "../../../../manager/MsgManager";
import { ShopRule } from "../../../../rules/ShopRule";
import { AIManager } from "../../../../scene/ai/AIManager";
import { ENpcEffect } from "../../../../../../Message/Public/ENpcEffect";
import { AIType } from "../../../../scene/ai/AIType";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
type int = number;
//class SkillRuneHandbookNormalItem
    
    export  class SkillRuneHandbookNormalItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public update(arg1: TRuneManual): void
        {
            var loc4=0;
            var loc5=null;
            var loc1=[arg1.levelOne, arg1.levelTwo, arg1.levelThree, arg1.levelFour];
            var loc2=0;
            while (loc2 < this._items.length) 
            {
                loc4 = int(loc1[loc2]);
                (loc5 = this._items[loc2] as SkillRuneHandbookRuneItem).update(loc4);
                loc5.toolTipData = RuneUtil.getRunesHandbookDesc(loc4);
                ++loc2;
            }
            this._txtName.htmlText = SkillRuneHandbookRuneItem(this._items[0]).item.itemData.htmlName;
            this._txtDesc.text = arg1.desc;
            var loc3=0;
            if (this.isCanGainFromShopMall(arg1.gain)) 
            {
                this._txtGainFromShopMall.visible = true;
            }
            else 
            {
                this._txtGainFromShopMall.visible = false;
                ++loc3;
            }
            if (this.isCanGainFromGuildShop(arg1.gain)) 
            {
                this._txtGainFromGuildShop.visible = true;
            }
            else 
            {
                this._txtGainFromGuildShop.visible = false;
                ++loc3;
            }
            if (this.isCanGainFromGankFight(arg1.gain)) 
            {
                this._txtGainFromGankFight.visible = true;
                this._spFlyFootBmp.visible = true;
            }
            else 
            {
                this._txtGainFromGankFight.visible = false;
                this._spFlyFootBmp.visible = false;
                ++loc3;
            }
            if (loc3 != 3) 
            {
                this._txtGain.visible = true;
            }
            else 
            {
                this._txtGain.visible = false;
            }
            return;
        }

        /* internal  */initView(): void
        {
            var loc3=null;
            var loc5=null;
            ObjCreate.createBg(0, 0, 495, 128, this);
            this._txtName = ObjCreate.createGTextField("", 9, 16, 200, 20, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.TileBg);
            loc1.x = 125;
            loc1.y = 11;
            this.addChild(loc1);
            this._txtDesc = ObjCreate.createGTextField("", 103, 15, 240, 20, this);
            var loc2=this._txtDesc.defaultTextFormat;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            this._txtDesc.defaultTextFormat = loc2;
            this._txtDesc.textColor = 1179426;
            this._txtGain = ObjCreate.createGTextField("", 317, 48, 220, 20, this);
            this._txtGain.htmlText = Language.getString(80097);
            this._txtGainFromShopMall = ObjCreate.createGTextField("", 317, 73, 220, 20, this);
            this._txtGainFromShopMall.htmlText = Language.getString(80098);
            this._txtGainFromShopMall.addEventListener(flash.events.MouseEvent.CLICK, this.clickLinkHandler);
            this._txtGainFromShopMall.addEventListener(flash.events.TextEvent.LINK, this.linkShopMallHandler);
            this._txtGainFromGuildShop = ObjCreate.createGTextField("", 378, 73, 220, 20, this);
            this._txtGainFromGuildShop.htmlText = Language.getString(80117);
            this._txtGainFromGuildShop.addEventListener(flash.events.MouseEvent.CLICK, this.clickLinkHandler);
            this._txtGainFromGuildShop.addEventListener(flash.events.TextEvent.LINK, this.linkShopMallHandler);
            this._txtGainFromGankFight = ObjCreate.createGTextField("", 317, 98, 220, 20, this);
            this._txtGainFromGankFight.htmlText = Language.getString(80099);
            this._txtGainFromGankFight.addEventListener(flash.events.MouseEvent.CLICK, this.clickLinkHandler);
            this._txtGainFromGankFight.addEventListener(flash.events.TextEvent.LINK, this.linkGankFightHandler);
            this._spFlyFootBmp = ObjectPool.getObject(FlyFootBmp);
            this._spFlyFootBmp.x = 384;
            this._spFlyFootBmp.y = 98;
            this.addChild(this._spFlyFootBmp);
            this._spFlyFootBmp.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyTransport);
            this._items = [];
            var loc4=0;
            while (loc4 < 4) 
            {
                (loc5 = new SkillRuneHandbookRuneItem()).y = 48;
                loc5.x = 10 + loc4 * 74;
                this.addChild(loc5);
                this._items.push(loc5);
                ++loc4;
            }
            return;
        }

        /* internal  */linkShopMallHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (arg1.text != "0") 
            {
                if (Cache.instance.guild.myGuildInfo != null) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenShop, 3));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(80116));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallShowToTab, ShopRule.ShopMallRune));
            }
            return;
        }

        /* internal  */isCanGainFromShopMall(arg1: int): Boolean
        {
            return (arg1 & this.CanGainFromShopMall) == this.CanGainFromShopMall;
        }

        /* internal  */isCanGainFromGuildShop(arg1: int): Boolean
        {
            return (arg1 & this.CanGainFromGuildShop) == this.CanGainFromGuildShop;
        }

        /* internal  */isCanGainFromGankFight(arg1: int): Boolean
        {
            return (arg1 & this.CanGainFromGankFight) == this.CanGainFromGankFight;
        }

        /* internal  */linkGankFightHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMeritExchange));
            return;
        }

        /* internal  */clickLinkHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onFlyTransport(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectMeritExchange), AIType.AI_Convey);
            return;
        }

        /* internal */ /* const */CanGainFromShopMall: int=1;

        /* internal */ /* const */CanGainFromGuildShop: int=2;

        /* internal */ /* const */CanGainFromGankFight: int=4;

        /* internal */ /* const */CanGainFromOther: int=8;

        /* internal */ /* var */_txtName: GTextFiled;

        /* internal */ /* var */_txtDesc: GTextFiled;

        /* internal */ /* var */_items: Array<any>;

        /* internal */ /* var */_txtGainFromShopMall: GTextFiled;

        /* internal */ /* var */_txtGainFromGuildShop: GTextFiled;

        /* internal */ /* var */_txtGainFromGankFight: GTextFiled;

        /* internal */ /* var */_spFlyFootBmp: FlyFootBmp;

        /* internal */ /* var */_txtGain: GTextFiled;
    }
